package com.acceptable.qucun.file.mapper;

import com.acceptable.qucun.file.entity.FileSource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.lang.NonNull;

import java.util.List;

@Mapper
public interface FileSourceMapper extends BaseMapper<FileSource> {
    @Select("SELECT file_md5, file_id, user_id FROM file_source WHERE file_md5 = #{fileMd5} ")
    List<FileSource> selectListByFileMd5(@NonNull String fileMd5);

    @Delete("DELETE FROM file_source WHERE file_id=#{source.fileId} AND user_id=#{source.userId} ")
    int deleteByFileId(@NonNull @Param("source") FileSource source);


    int deleteBatchByFileId(@NonNull @Param("userId") Integer userId,
                            @NonNull @Param("fileIdList") List<Long> fileIdList);

    @Delete("DELETE FROM file_source WHERE user_id=#{userId}")
    int deleteBatchByUserId(@NonNull @Param("userId") Integer userId);
}
